﻿using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Fast.Extensions.DatabaseAccessor.EntityFrameworkCore
{
    /// <summary>
    /// 更新仓储接口
    /// </summary>
    public interface IUpdateableRepository<TEntity> : IRootUpdateableRepository<TEntity, DefaultDbContextLocator>
        where TEntity : class, IRootEntity, new()
    {

    }
    /// <summary>
    /// 更新仓储接口
    /// </summary>
    public interface IRootUpdateableRepository<TEntity, TDbContextLocator> : IRootUpdateableRepository<TEntity>
        where TEntity : class, IRootEntity, new()
        where TDbContextLocator : class, IDbContextLocator
    {

    }
    /// <summary>
    /// 更新仓储接口
    /// </summary>
    public interface IRootUpdateableRepository<TEntity> : IRootRepositoryBase
        where TEntity : class, IRootEntity, new()
    {
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity"></param>
        void Update(TEntity entity);
        /// <summary>
        /// 更新一条记录并返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>代理中的实体</returns>
        EntityEntry<TEntity> UpdateWithReturnEntity(TEntity entity);
        /// <summary>
        /// 更新多条记录
        /// </summary>
        /// <param name="entities">多个实体</param>
        void Update(IEnumerable<TEntity> entities);
        /// <summary>
        /// 更新一条记录并立即提交
        /// </summary>
        /// <param name="entity"></param>
        void UpdateAndCommit(TEntity entity);
        /// <summary>
        /// 更新一条记录并立即提交，并返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>代理中的实体</returns>
        EntityEntry<TEntity> UpdateAndCommitWithReturnEntity(TEntity entity);
        /// <summary>
        /// 更新多条记录并立即提交
        /// </summary>
        /// <param name="entities">多个实体</param>
        void UpdateAndCommit(IEnumerable<TEntity> entities);
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity"></param>
        Task UpdateAsync(TEntity entity);
        /// <summary>
        /// 更新一条记录并返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>代理中的实体</returns>
        Task<EntityEntry<TEntity>> UpdateWithReturnEntityAsync(TEntity entity);
        /// <summary>
        /// 更新多条记录
        /// </summary>
        /// <param name="entities">多个实体</param>
        Task UpdateAsync(IEnumerable<TEntity> entities);
        /// <summary>
        /// 更新一条记录并立即提交
        /// </summary>
        /// <param name="entity"></param>
        Task UpdateAndCommitAsync(TEntity entity, CancellationToken cancellationToken = default);
        /// <summary>
        /// 更新一条记录并立即提交，并返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>代理中的实体</returns>
        Task<EntityEntry<TEntity>> UpdateAndCommitWithReturnEntityAsync(TEntity entity, CancellationToken cancellationToken = default);
        /// <summary>
        /// 更新多条记录并立即提交
        /// </summary>
        /// <param name="entities">多个实体</param>
        Task UpdateAndCommitAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
    }
}
